using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI; 
public class storeGird : MonoBehaviour
{
    public posGrid posGrid;
    public int soldierType;
    public GameObject UdpPlatform;
    // 建造时间
    public float coolDownTime;
    public int saleCoin;
    public bool flag;
    // Start is called before the first frame update
    void OnEnable()
    {
        flag=false;
        UdpPlatform=GameObject.Find("UdpServer");
        GetComponent<Button>().onClick.AddListener(TriggerMethod);
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    void TriggerMethod()
    {
        if(UdpPlatform.GetComponent<WebSocketDemo>().PlayerCoin<saleCoin)
        {
            transform.parent.gameObject.SetActive(false);
            return;
        }
        if(flag)
            return;
        Debug.Log(111);
        flag=true;
        UdpPlatform.GetComponent<WebSocketDemo>().PlayerCoin-=saleCoin;
        posGrid=transform.parent.gameObject.GetComponent<storeParam>().posGrid;
        posGrid.coolDownTime=coolDownTime;
        posGrid.coolDownTimeMax=coolDownTime;
        posGrid.soldierType=soldierType;
        
        transform.parent.gameObject.SetActive(false);
        
    }
}
